/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package podologia.beansDB;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 *
 * @author Hernan
 */
@Entity
@Table(name = "practicaxempleado")
@NamedQueries({@NamedQuery(name = "Practicaxempleado.findByIdPractica", query = "SELECT p FROM Practicaxempleado p WHERE p.practicaxempleadoPK.idPractica = :idPractica"), @NamedQuery(name = "Practicaxempleado.findByLegajo", query = "SELECT p FROM Practicaxempleado p WHERE p.practicaxempleadoPK.legajo = :legajo"), @NamedQuery(name = "Practicaxempleado.findByMatricula", query = "SELECT p FROM Practicaxempleado p WHERE p.matricula = :matricula")})
public class Practicaxempleado implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected PracticaxempleadoPK practicaxempleadoPK;
    @Column(name = "matricula")
    private String matricula;
    @OneToMany(cascade = CascadeType.MERGE, mappedBy = "practicaxempleado")
    private Collection<Turno> turnoCollection;
    @JoinColumn(name = "legajo", referencedColumnName = "legajo", insertable = false, updatable = false)
    @ManyToOne
    private Empleado empleado;
    @JoinColumn(name = "idPractica", referencedColumnName = "idPractica", insertable = false, updatable = false)
    @ManyToOne
    private Practica practica;

    public Practicaxempleado() {
    }

    public Practicaxempleado(PracticaxempleadoPK practicaxempleadoPK) {
        this.practicaxempleadoPK = practicaxempleadoPK;
    }

    public Practicaxempleado(int idPractica, int legajo) {
        this.practicaxempleadoPK = new PracticaxempleadoPK(idPractica, legajo);
    }

    public PracticaxempleadoPK getPracticaxempleadoPK() {
        return practicaxempleadoPK;
    }

    public void setPracticaxempleadoPK(PracticaxempleadoPK practicaxempleadoPK) {
        this.practicaxempleadoPK = practicaxempleadoPK;
    }

    public String getMatricula() {
        return matricula;
    }

    public void setMatricula(String matricula) {
        String oldMatricula = this.matricula;
        this.matricula = matricula;
        changeSupport.firePropertyChange("matricula", oldMatricula, matricula);
    }

    public Collection<Turno> getTurnoCollection() {
        return turnoCollection;
    }

    public void setTurnoCollection(Collection<Turno> turnoCollection) {
        this.turnoCollection = turnoCollection;
    }

    public Empleado getEmpleado() {
        return empleado;
    }

    public void setEmpleado(Empleado empleado) {
        Empleado oldEmpleado = this.empleado;
        this.empleado = empleado;
        changeSupport.firePropertyChange("empleado", oldEmpleado, empleado);
    }

    public Practica getPractica() {
        return practica;
    }

    public void setPractica(Practica practica) {
        Practica oldPractica = this.practica;
        this.practica = practica;
        changeSupport.firePropertyChange("practica", oldPractica, practica);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (practicaxempleadoPK != null ? practicaxempleadoPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Practicaxempleado)) {
            return false;
        }
        Practicaxempleado other = (Practicaxempleado) object;
        if ((this.practicaxempleadoPK == null && other.practicaxempleadoPK != null) || (this.practicaxempleadoPK != null && !this.practicaxempleadoPK.equals(other.practicaxempleadoPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return empleado.getIdPersona().getNombreCompleto();
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }

}
